package com.hhly.rabbitmq.simple;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.hhly.rabbitmq.RabbitMQUtil;
import com.rabbitmq.client.Channel;

/**
 * @desc 简单的发送与接收，没有特别的处理。
 * @author jiangwei
 * @date 2017年3月23日
 * @company 益彩网络科技公司
 * @version 1.0
 */
public class Send {
	final static String QUEUE_NAME = "hello";

	public static void main(String[] args) throws TimeoutException,IOException,InterruptedException {
		try {
			Channel channel = RabbitMQUtil.getChannel();
			channel.queueDeclare(QUEUE_NAME, false, false, false, null);
			int i = 0;
			for(;;){
				Thread.sleep(1000);
				String message = "Hello World!" + i++;
				//new AMQP.BasicProperties
				channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
				System.out.println(message);
			}
		} catch (Exception e) {
			Thread.sleep(5000);
			e.printStackTrace();
			Channel channel = RabbitMQUtil.getChannel();
			channel.queueDeclare(QUEUE_NAME, false, false, false, null);
			int i = 0;
			for(;;){
				Thread.sleep(1000);
				String message = "exception Hello World!" + i++;
				//new AMQP.BasicProperties
				channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
				System.out.println(message);
			}
		}
	}
}
